package com.hyjx.framework.component.interfaceservice.datauserservice;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import com.hyjx.framework.component.interfaceservice.InterFaceConstants;
import org.springframework.stereotype.Service;

import com.hyjx.framework.common.CommonUtil;
import com.hyjx.framework.common.util.StringHelper;
import com.hyjx.framework.component.interfaceservice.dataservice.DataServiceModel;
import com.hyjx.framework.component.interfaceservice.dataservice.SrvConditionModel;
import com.hyjx.framework.component.interfaceservice.datauser.DataUserModel;
import com.hyjx.framework.orm.BaseService;
import com.hyjx.framework.orm.dao.IBaseDao;
import com.hyjx.framework.orm.dao.Pager;

import net.sf.json.JSONObject;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class DataUserSServiceImpl extends BaseService implements DataUserSService{
	@Resource
	private IBaseDao dao;
	
	private static final String MODULE_NAME = "com.hyjx.framework.component.interfaceservice.datauserservice";
	
	public List queryALLAdmitInfo(String str) {
		
		return dao.queryObjectList(MODULE_NAME + ".showAdmit", str);
	}
	
	
	public List queryLimitALLUser(String str) {
		
		return dao.queryObjectList(MODULE_NAME + ".showUserInfo", str);
	}
	
	public List queryALLUser() {
		
		return dao.queryObjectList(MODULE_NAME + ".showAllUserInfo");
	}
	
	
	public String queryList(String model) {
		Pager pager = dao.getPager(MODULE_NAME + ".showAdmit", MODULE_NAME + ".showAdmitCount", model);
		return CommonUtil.getPageJsonStr(pager);
	}
	
	public Pager queryListA(String model) {
		Pager pager = dao.getPager(MODULE_NAME + ".showAdmit", MODULE_NAME + ".showAdmitCount", model);
		return pager;
	}
	public List queryListB(String model) {
		List list=null;
		list=dao.queryObjectList(MODULE_NAME + ".showAdmit",model);
	//	List list = dao.getPager(MODULE_NAME + ".showAdmit", MODULE_NAME + ".showAdmitCount", model);
		return list;
	}
	
	//根据用户登录名查找用户id
	public String queryUserIdByLogName(String model) {
		String userid = (String) dao.queryObject(MODULE_NAME + ".finduseridbylogname",model);
		return userid;
	}
	
	public int delAdmit(String id) {
		return dao.deleteObject(MODULE_NAME + ".deleteAdmit", id);
	}
	
	
	
	public String queryService(ServiceConditionModel model) {
		String str = dao.getPageJsonStr(MODULE_NAME + ".showServiceInfo", MODULE_NAME + ".showServiceInfoCount", model);
		return str;
	}
	
	
	public Pager getPageList(ServiceConditionModel model) {
		return  dao.getPageList(MODULE_NAME + ".showServiceInfo", MODULE_NAME + ".showServiceInfoCount", model);
	}
	
	
	public boolean addObject(DataUserServiceModel model){
		//这里生成user_service的主键id
		String id=StringHelper.getPrimaryKey();
		model.setId(id);
		boolean temp=dao.addObject(MODULE_NAME + ".insert_user_service", model);
		return temp;
	}
	
	
	
	
	public String findSqlDesc(String srvId,String para){
		DataServiceModel dsm=new DataServiceModel();
		dsm.setSrvid(srvId);
		SrvConditionModel scm=new SrvConditionModel();
		scm.setSrvid(srvId);
		String srvid=srvId;
		List dsmlist=dao.queryObjectList(InterFaceConstants.INTERFACE_MODULE_NAME + ".serchServiceDesc", srvid);
		List scmlist=dao.queryObjectList(InterFaceConstants.INTERFACE_MODULE_NAME + ".serchServiceDescCondition", srvid);
	//	List<Map<String,List>> fin= new ArrayList<Map<String,List>>() ;
	//	List<Map<String,String>> dsmlisttemp=new ArrayList<Map<String,String>>();
		List<Map<String,String>> scmlisttemp=new ArrayList<Map<String,String>>();
		
			DataServiceModel servicetemp=(DataServiceModel) dsmlist.get(0);
			Map<String,String>servicetempmap=new HashMap<String,String>();
			servicetempmap.put("servicename", servicetemp.getSrvname());
			
			if(servicetemp.getInterfacedesc()!=null){
				servicetempmap.put("interfacedesc",servicetemp.getInterfacedesc());
			}else{
				servicetempmap.put("interfacedesc","");

			}
		
		for(int i=0;i<scmlist.size();i++){
			SrvConditionModel temp=(SrvConditionModel) scmlist.get(i);
			Map<String,String>tempmap=new HashMap<String,String>();
			String parametername=temp.getParameter();
			
			String fl;
			
			if(para==null){
				fl=null;
			}else if(para.equals("")){
				fl=null;
			}else{
				Map map = (Map)JSONObject.toBean(JSONObject.fromObject(para), HashMap.class);
				fl=(String) map.get(parametername);
			}
			
			//String fl=(String) map.get(parametername);
			if(fl==null){
				tempmap.put("parametername", temp.getParameter());
				if(temp.getType().equals("1")){
					tempmap.put("paratype","字符串");
				}else{
					tempmap.put("paratype","整型");
				}
				
				if(temp.getRequired().equals("1")){
					tempmap.put("required", "是");
				}else{
					tempmap.put("required", "否");
				}
				
				if(temp.getParameter_means()!=null){
					tempmap.put("parameter_means", temp.getParameter_means());
				}else{
					tempmap.put("parameter_means", "");
				}
				scmlisttemp.add(tempmap);
			}
		}
		
		Map<String,Object>map1=new HashMap<String,Object>();
		
		map1.put("servicecondition", scmlisttemp);
		map1.put("service", servicetempmap);
		JSONObject json = JSONObject.fromObject(map1); 
		return json.toString();
		//return (String) dao.queryObject("interface_service.serchServiceDesc",srvId);
		
	}
	
	
	public List findUserById(DataUserModel model){
		return dao.queryObjectList(model.getModuleName() + ".queryList", model);
	}
	
	public DataUserModel findUserByIdModel(DataUserModel model){
		return (DataUserModel) dao.queryObject(model.getModuleName() + ".queryObject", model);
	}
	
	public DataServiceModel getDataServiceModel(DataServiceModel model){
		return (DataServiceModel) dao.queryObject(model.getModuleName() + ".getInfoById", model);
	}
	
	
	
	public int updateStatus(DataUserServiceModel model) {
		
		return dao.updateObject(MODULE_NAME + ".updatestatus", model);
	}
}
